package com.example.sjjg.utest

import android.content.Context
import androidx.test.core.app.ApplicationProvider
import com.example.sjjg.utest.app.UnitApp
import com.example.sjjg.utest.view.MainActivity
import com.google.common.truth.Truth.assertThat
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
import org.robolectric.Robolectric
import org.robolectric.RobolectricTestRunner
import org.robolectric.RuntimeEnvironment

@RunWith(RobolectricTestRunner::class)
class RobolectricTest {

    @Test
    fun readStringFromContext_LocalizedString() {
        val result: String = context.resources.getString(R.string.app_name)
        assertThat(result).isEqualTo(FAKE_STRING)
    }
    @Test
    fun clickingButton_shouldChangeMessage() {
        val activity: MainActivity = Robolectric.setupActivity(MainActivity::class.java)
        assertThat(activity.lifeCycle == 5)
    }


    //-----------------init-----------------
    lateinit var app    : UnitApp
    lateinit var context: Context
    val FAKE_STRING     = "Utest"

    @Before
    fun robolectric_setup(){
        app = RuntimeEnvironment.application as UnitApp
        println("setup application ")
    }
    @Before
    fun androidx_setup(){
        context = ApplicationProvider.getApplicationContext<UnitApp>()
        println("setup application ")
    }

}